package com.deyuanyun.pic.ctrl.controller.vo.exinsp;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.domain.ExinspOcgrade;
import com.deyuanyun.pic.ctrl.enumeration.TestingMethodEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.math.BigDecimal;

/**
 * 4外涂层分级评价
 */
public class ExinspOcgradeVO extends ExinspBaseVO<ExinspOcgrade> {

    // 管道名称
    private String pipeLineName;
    // 起点测试桩编号
    private String beginStationNumber;
    // 终点测试桩编号
    private String endStationNumber;
    // 起点测试桩id
    private String beginStationId;
    // 终点测试桩id
    private String endStationId;
    // 评价管段长度（m）
    public Long evaluationOfPipeLength;
    // 漏损点数量（个）
    public Long leakagePointNumber;
    // 外涂层分级评价_P（处/100m）
    private BigDecimal pvalue;
    // 外涂层分级评价_外涂层等级
    private Short coatingGrade;
    // 检测方法（DCVG、ACVG、OTHER）
    private String testingMethod;
    // 检测日期
    private String testingDate;
    // 检测单位
    private String testingCompany;

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getBeginStationNumber() {
        return beginStationNumber;
    }

    public void setBeginStationNumber(String beginStationNumber) {
        this.beginStationNumber = beginStationNumber;
    }

    public String getEndStationNumber() {
        return endStationNumber;
    }

    public void setEndStationNumber(String endStationNumber) {
        this.endStationNumber = endStationNumber;
    }

    public String getBeginStationId() {
        return beginStationId;
    }

    public void setBeginStationId(String beginStationId) {
        this.beginStationId = beginStationId;
    }

    public String getEndStationId() {
        return endStationId;
    }

    public void setEndStationId(String endStationId) {
        this.endStationId = endStationId;
    }

    public Long getEvaluationOfPipeLength() {
        return evaluationOfPipeLength;
    }

    public void setEvaluationOfPipeLength(Long evaluationOfPipeLength) {
        this.evaluationOfPipeLength = evaluationOfPipeLength;
    }

    public Long getLeakagePointNumber() {
        return leakagePointNumber;
    }

    public void setLeakagePointNumber(Long leakagePointNumber) {
        this.leakagePointNumber = leakagePointNumber;
    }

    public BigDecimal getPvalue() {
        return pvalue;
    }

    public void setPvalue(BigDecimal pvalue) {
        this.pvalue = pvalue;
    }

    public Short getCoatingGrade() {
        return coatingGrade;
    }

    public void setCoatingGrade(Short coatingGrade) {
        this.coatingGrade = coatingGrade;
    }

    public String getTestingMethod() {
        return testingMethod;
    }

    public void setTestingMethod(String testingMethod) {
        this.testingMethod = testingMethod;
    }

    public String getTestingDate() {
        return testingDate;
    }

    public void setTestingDate(String testingDate) {
        this.testingDate = testingDate;
    }

    public String getTestingCompany() {
        return testingCompany;
    }

    public void setTestingCompany(String testingCompany) {
        this.testingCompany = testingCompany;
    }

    EQPTBaseService eqptBaseService = SpringAppliction.getBean(EQPTBaseService.class);

    public void fromDomain(ExinspOcgrade domain) {

        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 起点测试桩编号
        EqptCptestStation eqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getBeginStationNumber());
        this.beginStationNumber = eqptCptestStation==null ? null : eqptCptestStation.getCustomNumber();
        // 终点测试桩编号
        EqptCptestStation endEqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getEndStationNumber());
        this.endStationNumber = endEqptCptestStation==null ? null : endEqptCptestStation.getCustomNumber();
        // 起点测试桩id
        this.beginStationId = domain.getBeginStationNumber();
        // 终点测试桩id
        this.endStationId = domain.getEndStationNumber();
        // 评价管段长度（m）
        this.evaluationOfPipeLength = domain.getEvaluationOfPipeLength();
        // 漏损点数量（个）
        this.leakagePointNumber = domain.getLeakagePointNumber();
        // 外涂层分级评价_P（处/100m）
        this.pvalue = domain.getPvalue();
        // 外涂层分级评价_外涂层等级
        this.coatingGrade = domain.getCoatingGrade();
        // 检测方法（DCVG、ACVG、OTHER）
        this.testingMethod = TestingMethodEnum.getLabel(domain.getTestingMethod());
        // 检测日期
        this.testingDate = DateFormat.format(domain.getTestingDate());
        // 检测单位
        this.testingCompany = domain.getTestingCompany();

        super.fromDomain(domain.getId(), domain.getRecorder(), domain.getRecordTime(), domain.getRemarks());
    }

    public Page<ExinspOcgradeVO> fromDomainList(Page<ExinspOcgrade> domainList) {

        Page<ExinspOcgradeVO> list = new Page<ExinspOcgradeVO>();
        for (ExinspOcgrade exinspOcgrade : domainList) {
            ExinspOcgradeVO exinspOcgradeVO = new ExinspOcgradeVO();
            exinspOcgradeVO.fromDomain(exinspOcgrade);
            list.add(exinspOcgradeVO);
        }
        BaseVOUtil.converterPage(domainList, list);
        return list;
    }
}